let fs = require('fs');
let path = require('path');
let router = require('koa-router')();
function x(dir) {
    let files = fs.readdirSync(dir);
    let coo = files.filter((name) => {
        return name.endsWith('.js') && name !== 'index.js';


    });
    return coo;
}
function y(files,uuu) {
    files.forEach(item => {
        let tmp = path.join(uuu, item);
        let route = require(tmp);
        for (let key in route) {
            let type = route[key][0];
            let fn = route[key][1];
            if (type === 'get') {
                router.get(key, fn);
            } else {
                router.post(key, fn);
            }
           
        }
    })
}



 
module.exports = function (curr) {
    let dir = curr || '/controllers';
    let root = path.resolve('.');
    let cotrnnnn = path.join(root, dir)
    let files = x(cotrnnnn);
    y(files, cotrnnnn);
    return router.routes();
}